package cn.john.hrm.controller;

import cn.john.hrm.dto.SmsDto;
import cn.john.hrm.service.IVerifyCodeService;
import cn.john.hrm.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.io.IOException;

@RestController
@RequestMapping("/verifycode")
public class VerifyCodeController {
    @Autowired
    private IVerifyCodeService verifyCodeService;

    /**
     * 图片验证码
     * @param key
     * @return
     * @throws IOException
     */
    @RequestMapping("/imageCode/{key}")
    public AjaxResult imageCode(@PathVariable("key") String key) throws IOException {
        return verifyCodeService.imageCode(key);
    }

    /**
     * 手机短信验证码
     * @param smsDto
     * @return
     */
    @RequestMapping("/sendSmsCode")
    public AjaxResult sendSmsCode(@RequestBody @Valid SmsDto smsDto) {
        return verifyCodeService.sendSmsCode(smsDto);
    }
}
